package com.simba.server.commands.impl.record;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class RecordPacketOffHistoryCmd implements ICommand
{
	public static final String NAME = "RecordPacketOffHistoryCmd";

	private final String columns = ""
			+ "barcode,sorterId,plcId,serverSlots,droppedSlot,sortingId,boxCode,turnNumber,obrNo,"
			+ "errorCodeSVR,errorCodePLC,packetOnTime,packetOffTime,uploadFlag, uploadNum, slotDistrict, "
			+ "planId, roadSlot, roadSlotName, syncFlag, weight,length,width,height,volume";

	private final int id;
	private final String sql = "insert into tt_packet_off_info_history(" + columns + ") select "
			+ columns + " from tt_packet_off_info where id=?;";

	public RecordPacketOffHistoryCmd(int id)
	{
		this.id = id;
	}

	@Override
	public String getName()
	{
		return RecordPacketOffHistoryCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;
			dbOperator.prepareStatement(this.sql);
			dbOperator.setInt(1, id);
			int rs = dbOperator.executeUpdate();

			if (rs > 0)
			{
				ret = true;
			}
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}

}
